package com.example.jiaju.ui;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.jiaju.R;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

/**
 * 消息页面  内嵌3个Fragment
 */
public class MessageFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_message, container, false);
        //小标题
        TabLayout message_tab=view.findViewById(R.id.message_tab);
        //小标题内容展示
        ViewPager2 message_viewpager=view.findViewById(R.id.message_viewpager);



        message_viewpager.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                switch(position){
//                    case 0:return new InteractionFragment();//互动
                    default:return new ConsultFragment();//咨询
//                    default:return new NotificationFragment();//通知
                }
            }
            @Override
            public int getItemCount() {
                return 1;
            }
        });

        new TabLayoutMediator(message_tab,message_viewpager,(tab, position) -> {
            switch (position){
//                case 0:tab.setText("互动");break;
//                case 2:tab.setText("通知");break;
                default:tab.setText("咨询");break;
            }
        }).attach();
        //默认是咨询
        message_tab.getTabAt(0).select();
        return view;
    }
}